/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package solicitudesfiec;

import ec.edu.espol.academico.webservices.DirectorioEspol;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.mail.Session;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.ws.WebServiceRef;
import solicitudesfiec.autenticacion.AutenticadorRemote;

/**
 *
 * @author Larry
 */
public class Main {

//appclient -client client-jar/converterClient.jar

    public Main() {
    }
    @EJB
    static AutenticadorRemote autenticador2;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
//        try {
        Main m = new Main();
        m.prueba3();
//        } catch (IOException ex) {
//            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
//        }
    }

    public void prueba() throws IOException {
        boolean seAutentico;
        char[] password = {'2', '0', '0', '2', '1', '1', '3', '2', '5'};
        try {
            Properties props = new Properties();
            props.load(new FileInputStream("jndi.properties"));
            InitialContext ic = new InitialContext(props);

            System.out.println("Hola");
            System.out.println("java.naming.provider.url: " + ic.getEnvironment().get("java.naming.provider.url"));
            System.out.println("java.naming.factory.initial: " + ic.getEnvironment().get("java.naming.factory.initial"));

            autenticador2 = (AutenticadorRemote) ic.lookup("solicitudesfiec.autenticacion.AutenticadorRemote");
            System.out.println("AutenticadorRemote: " + AutenticadorRemote.class.getName());
            System.out.println("autenticador2:" + autenticador2);
            //System.out.println("autenticador: "+autenticador);
            autenticador2.holaMundo("Larry", password);

            seAutentico = autenticador2.autenticarEspol("lbeltran", password);
            System.out.println("Se autentico: " + seAutentico);
        } catch (NamingException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void prueba2() {
        try {
            InitialContext ic = new InitialContext();
            Object obj = ic.lookup("mail/MySession");
//            Object obj =ic.lookup("mail/MailSessionFIEC");
            System.out.println("MailSessionFIEC: " + (Session) obj);
        } catch (NamingException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void prueba3() {

        try { // Call Web Service Operation
       	    ec.edu.espol.academico.webservices.DirectorioEspol service = new ec.edu.espol.academico.webservices.DirectorioEspol();
            ec.edu.espol.academico.webservices.DirectorioEspolSoap port = service.getDirectorioEspolSoap();
            // TODO initialize WS operation arguments here
            java.lang.String varUser = "lbeltran";
            java.lang.String varContrasenia = "200211324";
            // TODO process result here
            ec.edu.espol.academico.webservices.DatosUsuarioResponse.DatosUsuarioResult result = port.datosUsuario(varUser, varContrasenia);
            System.out.println("Result = " + result);
        } catch (Exception ex) {
            ex.printStackTrace();
            // TODO handle custom exceptions here
        }

    }
}
